<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script>
 $(function(){
	 var pageNo=1, total=1;
	 var sname="",tel="",start="",end="";
	 	
	function doQuery(){ 
		  $.get("studentsearch.do",{pageNo:pageNo,tel:tel,sname:sname,datestart:start,dateend:end},function(p){
			 total=p.totalPage;
			 
			 $("#paging #go").val(p.pageNo);
			 $("#paging #total").text(total);
			 
			 var t=$("#stuTab");
			 t.find("tr:gt(0)").remove();
			 $.each(p.datas,function(i,d){
				 t.append("<tr><td>"+d.stuno+"</td><td>"+d.sname+"</td><td>"+d.telephone+"</td><td>"+d.gname+"</td><td>"+d.sex+"</td><td>"+d.qq+"</td><td>"+d.wechat+"</td><td>"+(d.enterdate==null?"":d.enterdate)+"</td><td><a href='#' class='del' stuno='"+d.stuno+"'>删除</a>  <a href='#' class='update' stuno='"+d.stuno+"'>修改</a></td></tr>");
			 });
		 }); 
	}
	doQuery();
	//查询提交
	$("#search").click(function(){
		pageNo=1;
		sname=$("input[name=sname]").val();
		tel=$("input[name=tel]").val();
		start=$("input[name=datestart]").val();
		end=$("input[name=dateend]").val();
		doQuery();
		return false;
	});
	//首页
	$("#paging a#first").click(function(){
		pageNo=1;
		doQuery();
		return false;
	});
	//前一页
	$("#paging a#prev").click(function(){
		if(pageNo<1){
			alert("已经是首页了");
			return false;
		}
		pageNo--;
		doQuery();
		return false;
	});
	$("#paging a#next").click(function(){
		if(pageNo>=total){
			alert("已经是最后一页了");
			return false;
		}
		pageNo++;
		doQuery();
		return false;
	});
	$("#paging a#last").click(function(){
		pageNo=total;
		
		doQuery();
		return false;
	});
	//go
	$("input#go").keyup(function(event){ 
		 if(event.keyCode==13)//回车
		 {
			 if(this.value==""||isNaN(this.value)){
				 return false;
			 } 
			 if($(this).val()<1||$(this).val()>total){
				// alert("没有此页1");
				 return false;
			 }
			 pageNo=$(this).val();
			 doQuery();
		 }
	 }).blur(function(){
		 if(this.value==""||isNaN(this.value)){
			 return false;
		 } 
		 if($(this).val()<1||$(this).val()>total){
			// alert("没有此页2");
			 return false;
		 }
		 pageNo=$(this).val();
		 doQuery();
	 });
	$("#stuTab").on("click",".del",function(){
		
		var stuno=$(this).attr("stuno");//$(this).parent().parent().find("td:eq(0)").text();
		alert("del:"+stuno);
		//confirm("");
		return false;
	});
	$("#stuTab").on("click",".update",function(){
		alert("update");
		var stuno=$(this).attr("stuno");
		window.location="updateStudent.html?"+stuno;
		//location.search   ?45
		return false;
	});
 });
</script>
</head>
 <body>
  <h2>学生信息</h2>
  <p>
<form method="get" action="students.html" id="searchForm">
 <input type="search" name="sname"   placeholder="用户名"/>
 <input type="search" name="tel"  placeholder="手机号"/> 
 <input type="search" name="datestart"   placeholder="入学时间起点"/> 
 <input type="search" name="dateend"   placeholder="入学时间终点"/>   
 <input type="submit" value="search" id="search"/>
 </form>
</p>
<table border="1" cellpadding="0" cellspacing="0" id="stuTab">
<tr>
 <td>学号</td><td>姓名</td><td>手机号</td><td>年级</td>
 <td>性别</td><td>QQ</td><td>微信号</td><td>入学日期</td>
 <td>操作</td>
</tr>
  </table>
  <p align="center" id="paging">
 <a href="#" id="first">首页</a>

 <a href="#" id="prev">上一页</a>

 <input type="number" min="1" id="go" name="go" style="width:30px" value=""/>/<span id="total"></span>

 <a href="#" id="next">下一页</a>

 <a href="#" id="last">末页</a>
</p>
 </body>
</html>
